﻿using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x02000566 RID: 1382
	public class AnimeControl : MonoBehaviour
	{
		// Token: 0x17000447 RID: 1095
		// (get) Token: 0x0600233E RID: 9022 RVA: 0x000D4B88 File Offset: 0x000D2D88
		// (set) Token: 0x0600233F RID: 9023 RVA: 0x000D4B90 File Offset: 0x000D2D90
		public ObjectCtrlInfo objectCtrlInfo
		{
			get
			{
				return this.m_ObjectCtrlInfo;
			}
			set
			{
				this.m_ObjectCtrlInfo = value;
				if (this.m_ObjectCtrlInfo != null)
				{
					this.UpdateInfo();
				}
			}
		}

		// Token: 0x17000448 RID: 1096
		// (set) Token: 0x06002340 RID: 9024 RVA: 0x000D4BAC File Offset: 0x000D2DAC
		public bool active
		{
			set
			{
				if (base.gameObject.activeSelf != value)
				{
					base.gameObject.SetActive(value);
				}
			}
		}

		// Token: 0x06002341 RID: 9025 RVA: 0x000D4BCC File Offset: 0x000D2DCC
		private void OnValueChangedSpeed(float _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.arrayTarget.IsNullOrEmpty<ObjectCtrlInfo>())
			{
				this.OnPointerDownSpeed(null);
			}
			for (int i = 0; i < this.num; i++)
			{
				this.arrayTarget[i].animeSpeed = _value;
			}
			this.inputSpeed.text = _value.ToString("0.00");
		}

		// Token: 0x06002342 RID: 9026 RVA: 0x000D4C38 File Offset: 0x000D2E38
		private void OnPointerDownSpeed(BaseEventData _data)
		{
			if (!this.arrayTarget.IsNullOrEmpty<ObjectCtrlInfo>())
			{
				return;
			}
			this.arrayTarget = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			where v.kind == 0 || v.kind == 1
			select v).ToArray<ObjectCtrlInfo>();
			this.num = this.arrayTarget.Length;
			this.oldValue = (from v in this.arrayTarget
			select v.animeSpeed).ToArray<float>();
		}

		// Token: 0x06002343 RID: 9027 RVA: 0x000D4CD4 File Offset: 0x000D2ED4
		private void OnPointerUpSpeed(BaseEventData _data)
		{
			if (this.arrayTarget.Length == 0)
			{
				return;
			}
			Singleton<UndoRedoManager>.Instance.Do(new AnimeCommand.SpeedCommand((from v in this.arrayTarget
			select v.objectInfo.dicKey).ToArray<int>(), this.sliderSpeed.value, this.oldValue));
			this.arrayTarget = null;
			this.num = 0;
		}

		// Token: 0x06002344 RID: 9028 RVA: 0x000D4D4C File Offset: 0x000D2F4C
		private void OnEndEditSpeed(string _text)
		{
			float num = Mathf.Clamp(Utility.StringToFloat(_text), 0f, 3f);
			this.arrayTarget = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			where v.kind == 0 || v.kind == 1
			select v).ToArray<ObjectCtrlInfo>();
			this.num = this.arrayTarget.Length;
			this.oldValue = (from v in this.arrayTarget
			select v.animeSpeed).ToArray<float>();
			Singleton<UndoRedoManager>.Instance.Do(new AnimeCommand.SpeedCommand((from v in this.arrayTarget
			select v.objectInfo.dicKey).ToArray<int>(), num, this.oldValue));
			this.isUpdateInfo = true;
			this.sliderSpeed.value = num;
			this.inputSpeed.text = num.ToString("0.00");
			this.isUpdateInfo = false;
			this.arrayTarget = null;
			this.num = 0;
		}

		// Token: 0x06002345 RID: 9029 RVA: 0x000D4E70 File Offset: 0x000D3070
		private void OnPointerDownPattern()
		{
			if (!this.arrayTarget.IsNullOrEmpty<ObjectCtrlInfo>())
			{
				return;
			}
			this.arrayTarget = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			where v.kind == 0
			select v).ToArray<ObjectCtrlInfo>();
			this.num = this.arrayTarget.Length;
			this.oldPattern = (from v in this.arrayTarget
			select (v as OCIChar).animePattern).ToArray<Vector2>();
		}

		// Token: 0x06002346 RID: 9030 RVA: 0x000D4F0C File Offset: 0x000D310C
		private void OnPointerUpPattern()
		{
			if (this.arrayTarget.Length == 0)
			{
				return;
			}
			Vector2 normalize = this.mixPad.normalize;
			normalize.Set(Mathf.Lerp(-1f, 1f, normalize.x), Mathf.Lerp(-1f, 1f, normalize.y));
			Singleton<UndoRedoManager>.Instance.Do(new AnimeCommand.PatternCommand((from v in this.arrayTarget
			select v.objectInfo.dicKey).ToArray<int>(), normalize, this.oldPattern));
		}

		// Token: 0x06002347 RID: 9031 RVA: 0x000D4FAC File Offset: 0x000D31AC
		private void OnValueChangedPattern(Vector2 _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.arrayTarget.IsNullOrEmpty<ObjectCtrlInfo>())
			{
				this.OnPointerDownPattern();
			}
			Vector2 animePattern = new Vector2(Mathf.Lerp(-1f, 1f, _value.x), Mathf.Lerp(-1f, 1f, _value.y));
			for (int i = 0; i < this.num; i++)
			{
				(this.arrayTarget[i] as OCIChar).animePattern = animePattern;
			}
		}

		// Token: 0x06002348 RID: 9032 RVA: 0x000D5038 File Offset: 0x000D3238
		private void ChangedOptionParam(float _value, int _kind)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.arrayTarget.IsNullOrEmpty<ObjectCtrlInfo>())
			{
				this.DownOptionParam(null, _kind);
			}
			float num = Mathf.Lerp(0f, 1f, _value);
			for (int i = 0; i < this.num; i++)
			{
				OCIChar ocichar = this.arrayTarget[i] as OCIChar;
				if (_kind == 0)
				{
					ocichar.animeOptionParam1 = num;
				}
				else
				{
					ocichar.animeOptionParam2 = num;
				}
			}
			this.inputOptionParam[_kind].text = num.ToString("0.00");
		}

		// Token: 0x06002349 RID: 9033 RVA: 0x000D50D4 File Offset: 0x000D32D4
		private void DownOptionParam(BaseEventData _data, int _kind)
		{
			if (!this.arrayTarget.IsNullOrEmpty<ObjectCtrlInfo>())
			{
				return;
			}
			this.arrayTarget = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			where v.kind == 0
			select v).ToArray<ObjectCtrlInfo>();
			this.num = this.arrayTarget.Length;
			this.oldValue = (from v in this.arrayTarget
			select (v as OCIChar).animeOptionParam[_kind]).ToArray<float>();
		}

		// Token: 0x0600234A RID: 9034 RVA: 0x000D516C File Offset: 0x000D336C
		private void UpOptionParam(BaseEventData _data, int _kind)
		{
			if (this.arrayTarget.Length == 0)
			{
				return;
			}
			float value = Mathf.Lerp(0f, 1f, this.sliderOptionParam[_kind].value);
			Singleton<UndoRedoManager>.Instance.Do(new AnimeCommand.OptionParamCommand((from v in this.arrayTarget
			select v.objectInfo.dicKey).ToArray<int>(), value, this.oldValue, _kind));
		}

		// Token: 0x0600234B RID: 9035 RVA: 0x000D51E8 File Offset: 0x000D33E8
		private void EndEditOptionParam(string _text, int _kind)
		{
			float value = Mathf.Clamp(Utility.StringToFloat(_text), 0f, 1f);
			this.arrayTarget = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			where v.kind == 0
			select v).ToArray<ObjectCtrlInfo>();
			this.num = this.arrayTarget.Length;
			this.oldValue = (from v in this.arrayTarget
			select (v as OCIChar).animeOptionParam[_kind]).ToArray<float>();
			Singleton<UndoRedoManager>.Instance.Do(new AnimeCommand.OptionParamCommand((from v in this.arrayTarget
			select v.objectInfo.dicKey).ToArray<int>(), value, this.oldValue, _kind));
			this.isUpdateInfo = true;
			this.sliderOptionParam[_kind].value = value;
			this.inputOptionParam[_kind].text = value.ToString("0.00");
			this.isUpdateInfo = false;
			this.arrayTarget = null;
			this.num = 0;
		}

		// Token: 0x0600234C RID: 9036 RVA: 0x000D531C File Offset: 0x000D351C
		private void OnValueChangedOption(bool _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			OCIChar ocichar = this.m_ObjectCtrlInfo as OCIChar;
			if (ocichar != null)
			{
				ocichar.optionItemCtrl.visible = _value;
			}
		}

		// Token: 0x0600234D RID: 9037 RVA: 0x000D5354 File Offset: 0x000D3554
		private void OnValueChangedLoop(bool _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			OCIChar ocichar = this.m_ObjectCtrlInfo as OCIChar;
			if (ocichar != null)
			{
				ocichar.charAnimeCtrl.isForceLoop = _value;
			}
		}

		// Token: 0x0600234E RID: 9038 RVA: 0x000D538C File Offset: 0x000D358C
		private void OnClickRestart()
		{
			OCIChar[] array = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			select v as OCIChar into v
			where v != null
			select v).ToArray<OCIChar>();
			for (int i = 0; i < array.Length; i++)
			{
				array[i].RestartAnime();
			}
			OCIItem[] array2 = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			select v as OCIItem into v
			where v != null
			select v).ToArray<OCIItem>();
			for (int j = 0; j < array2.Length; j++)
			{
				array2[j].RestartAnime();
			}
		}

		// Token: 0x0600234F RID: 9039 RVA: 0x000D5484 File Offset: 0x000D3684
		private void OnClickAllRestart()
		{
			OCIChar[] array = (from v in Singleton<Studio>.Instance.dicObjectCtrl
			where v.Value.kind == 0
			select v.Value as OCIChar).ToArray<OCIChar>();
			for (int i = 0; i < array.Length; i++)
			{
				array[i].RestartAnime();
			}
			OCIItem[] array2 = (from v in Singleton<Studio>.Instance.dicObjectCtrl
			where v.Value.kind == 1
			select v.Value as OCIItem).ToArray<OCIItem>();
			for (int j = 0; j < array2.Length; j++)
			{
				array2[j].RestartAnime();
			}
		}

		// Token: 0x06002350 RID: 9040 RVA: 0x000D5574 File Offset: 0x000D3774
		private void OnClickCopy()
		{
			OCIChar[] array = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			select v as OCIChar into v
			where v != null
			select v).ToArray<OCIChar>();
			if (array.Length == 0)
			{
				return;
			}
			this.animeInfo.Copy(array[0].oiCharInfo.animeInfo);
			this.sex = array[0].oiCharInfo.sex;
		}

		// Token: 0x06002351 RID: 9041 RVA: 0x000D5610 File Offset: 0x000D3810
		private void OnClickPaste()
		{
			if (this.sex == -1 || !this.animeInfo.exist)
			{
				return;
			}
			OCIChar[] array = (from v in Singleton<Studio>.Instance.treeNodeCtrl.selectObjectCtrl
			select v as OCIChar into v
			where v != null
			where v.oiCharInfo.sex == this.sex
			select v).ToArray<OCIChar>();
			for (int i = 0; i < array.Length; i++)
			{
				array[i].LoadAnime(this.animeInfo.group, this.animeInfo.category, this.animeInfo.no, 0f);
			}
		}

		// Token: 0x06002352 RID: 9042 RVA: 0x000D56E8 File Offset: 0x000D38E8
		private void Init()
		{
			this.sliderSpeed.onValueChanged.AddListener(new UnityAction<float>(this.OnValueChangedSpeed));
			this.AddEventTrigger(this.eventSpeed, EventTriggerType.PointerDown, new UnityAction<BaseEventData>(this.OnPointerDownSpeed));
			this.AddEventTrigger(this.eventSpeed, EventTriggerType.PointerUp, new UnityAction<BaseEventData>(this.OnPointerUpSpeed));
			this.inputSpeed.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditSpeed));
			this.mixPad.Init();
			MixPad mixPad = this.mixPad;
			mixPad.onPointerDown = (MixPad.OnPointerDelegate)Delegate.Combine(mixPad.onPointerDown, new MixPad.OnPointerDelegate(this.OnPointerDownPattern));
			MixPad mixPad2 = this.mixPad;
			mixPad2.onPointerUp = (MixPad.OnPointerDelegate)Delegate.Combine(mixPad2.onPointerUp, new MixPad.OnPointerDelegate(this.OnPointerUpPattern));
			MixPad mixPad3 = this.mixPad;
			mixPad3.onValueChanged = (MixPad.OnValueChangedDelegate)Delegate.Combine(mixPad3.onValueChanged, new MixPad.OnValueChangedDelegate(this.OnValueChangedPattern));
			for (int i = 0; i < 2; i++)
			{
				int kind = i;
				this.sliderOptionParam[i].onValueChanged.AddListener(delegate(float t)
				{
					this.ChangedOptionParam(t, kind);
				});
				this.AddEventTrigger(this.eventOptionParam[i], EventTriggerType.PointerDown, delegate(BaseEventData d)
				{
					this.DownOptionParam(d, kind);
				});
				this.AddEventTrigger(this.eventOptionParam[i], EventTriggerType.PointerUp, delegate(BaseEventData d)
				{
					this.UpOptionParam(d, kind);
				});
				this.inputOptionParam[i].onEndEdit.AddListener(delegate(string s)
				{
					this.EndEditOptionParam(s, kind);
				});
			}
			this.toggleOption.onValueChanged.AddListener(new UnityAction<bool>(this.OnValueChangedOption));
			this.toggleLoop.onValueChanged.AddListener(new UnityAction<bool>(this.OnValueChangedLoop));
			this.buttons[0].onClick.AddListener(new UnityAction(this.OnClickRestart));
			this.buttons[1].onClick.AddListener(new UnityAction(this.OnClickAllRestart));
			this.buttons[2].onClick.AddListener(new UnityAction(this.OnClickCopy));
			this.buttons[3].onClick.AddListener(new UnityAction(this.OnClickPaste));
		}

		// Token: 0x06002353 RID: 9043 RVA: 0x000D5928 File Offset: 0x000D3B28
		public void UpdateInfo()
		{
			this.isUpdateInfo = true;
			this.arrayTarget = null;
			bool flag = this.m_ObjectCtrlInfo.kind == 0;
			OCIChar ocichar = this.m_ObjectCtrlInfo as OCIChar;
			bool flag2 = flag && ocichar.oiCharInfo.sex == 0;
			this.sliderSpeed.value = this.m_ObjectCtrlInfo.animeSpeed;
			this.inputSpeed.text = this.m_ObjectCtrlInfo.animeSpeed.ToString("0.00");
			this.mixPad.SetNormalize((!flag) ? 0.5f : Mathf.InverseLerp(-1f, 1f, ocichar.animePattern1), (!flag) ? 0.5f : Mathf.InverseLerp(-1f, 1f, ocichar.animePattern2));
			for (int i = 0; i < 2; i++)
			{
				this.sliderOptionParam[i].interactable = flag2;
				this.inputOptionParam[i].interactable = flag2;
				this.sliderOptionParam[i].value = ((!flag2) ? 0.5f : ocichar.animeOptionParam[i]);
				this.inputOptionParam[i].text = ((!flag2) ? "-" : ocichar.animeOptionParam[i].ToString("0.00"));
			}
			this.toggleOption.interactable = flag;
			this.toggleOption.isOn = (flag && ocichar.optionItemCtrl.visible);
			this.toggleLoop.interactable = flag;
			this.toggleLoop.isOn = (flag && ocichar.charAnimeCtrl.isForceLoop);
			this.buttons[2].interactable = flag;
			this.buttons[3].interactable = flag;
			this.isUpdateInfo = false;
		}

		// Token: 0x06002354 RID: 9044 RVA: 0x000D5B18 File Offset: 0x000D3D18
		private void AddEventTrigger(EventTrigger _event, EventTriggerType _type, UnityAction<BaseEventData> _action)
		{
			EventTrigger.Entry entry = new EventTrigger.Entry();
			entry.eventID = _type;
			entry.callback.AddListener(_action);
			_event.triggers.Add(entry);
		}

		// Token: 0x06002355 RID: 9045 RVA: 0x000D5B4C File Offset: 0x000D3D4C
		private void Awake()
		{
			this.arrayTarget = null;
			this.num = 0;
			this.Init();
			base.gameObject.SetActive(false);
		}

		// Token: 0x04002432 RID: 9266
		[SerializeField]
		private Slider sliderSpeed;

		// Token: 0x04002433 RID: 9267
		[SerializeField]
		private EventTrigger eventSpeed;

		// Token: 0x04002434 RID: 9268
		[SerializeField]
		private InputField inputSpeed;

		// Token: 0x04002435 RID: 9269
		[SerializeField]
		private MixPad mixPad;

		// Token: 0x04002436 RID: 9270
		[SerializeField]
		private Slider[] sliderOptionParam;

		// Token: 0x04002437 RID: 9271
		[SerializeField]
		private EventTrigger[] eventOptionParam;

		// Token: 0x04002438 RID: 9272
		[SerializeField]
		private InputField[] inputOptionParam;

		// Token: 0x04002439 RID: 9273
		[SerializeField]
		private Toggle toggleOption;

		// Token: 0x0400243A RID: 9274
		[SerializeField]
		private Toggle toggleLoop;

		// Token: 0x0400243B RID: 9275
		[SerializeField]
		private Button[] buttons;

		// Token: 0x0400243C RID: 9276
		private ObjectCtrlInfo m_ObjectCtrlInfo;

		// Token: 0x0400243D RID: 9277
		private bool isUpdateInfo;

		// Token: 0x0400243E RID: 9278
		private ObjectCtrlInfo[] arrayTarget;

		// Token: 0x0400243F RID: 9279
		private int num;

		// Token: 0x04002440 RID: 9280
		private float[] oldValue;

		// Token: 0x04002441 RID: 9281
		private Vector2[] oldPattern;

		// Token: 0x04002442 RID: 9282
		private int sex = -1;

		// Token: 0x04002443 RID: 9283
		private OICharInfo.AnimeInfo animeInfo = new OICharInfo.AnimeInfo();
	}
}
